<?php

namespace Common\Model;

/**
 * Description of HotelRoomCheckModel
 * 
 * @author wenhui
 */
class HotelRoomCheckModel extends BaseModel {

    protected $trueTableName = 'tb_hotel_room_check';

    /**
     * 添加客栈记一笔数据
     * @modify wenhui 2017-12-19
     * @param array $data 封装好的信息
     * @return boolean          执行结果
     */
    public function addAllInfo($data) {
        $result = $this->addAll($data);

        return $result;
    }

    /**
     * 子订单id 获取记录
     * @modify wenhui 2017-12-19
     * @param int $subOrderId 子订单id
     * @return array  $data       执行结果
     */
    public function getInfoBySubOrderId($subOrderId) {
        $options['orderroom_id'] = $subOrderId;
        $options['isdelete'] = NOT_DELETE;

        $data = $this->where($options)->find();
        return $data;
    }

    /**
     * 客栈id 获取记录
     * @modify wenhui 2017-12-19
     * @param array $hotelId 客栈id
     * @return array  $data    执行结果
     */
    public function getInfoByhotelId($hotelId, $type = null) {
        if (is_array($hotelId)) {
            $hotelId = implode(',', $hotelId);
        }

        if (strpos($hotelId, ',') !== false) {
            $options['hotelentity_id'] = array('in', $hotelId);
        } else {
            $options['hotelentity_id'] = $hotelId;
        }

        if (!is_null($type)) {
            $options['type'] = $type;
        }

        $options['isdelete'] = NOT_DELETE;

        $data = $this->where($options)->select();
        return $data;
    }

    /**
     * 客栈id 获取记录
     * @modify wenhui 2017-12-19
     * @param int $id 
     * @return array  $data 执行结果
     */
    public function getCheckInfoById($id) {
        $options['id'] = $id;
        $options['isdelete'] = NOT_DELETE;

        $data = $this->where($options)->find();
        return $data;
    }

    /**
     * 修改数据
     * @modify wenhui 2017-12-19
     * @param inetegr $id  id
     * @param int $userId 用户id
     * @param string $remark 详情
     * @param int $type 消息状态 0=未查 1=已查 2=知道了 默认0
     */
    public function saveInfo($id, $userId = null, $remark = null, $type = null) {
        $options = array(
            'id' => $id,
        );

        $data = array();
        if (!empty($userId)) {
            $data['adminlogin_id_check'] = $userId;
        }
        if (!is_null($remark)) {
            $data['remark'] = $remark;
        }
        if (!is_null($type)) {
            $data['type'] = $type;
        }

        $result = $this->where($options)->save($data);
        return $result === false ? false : true;
    }

    /**
     * 删除数据
     * @modify wenhui 2017-12-19
     * @param inetegr $id  id
     */
    public function deleteInfo($ids) {
        if (is_array($ids)) {
            $ids = implode(',', $ids);
        }

        if (strpos($ids, ',') !== false) {
            $options['id'] = array('in', $ids);
        } else {
            $options['id'] = $ids;
        }

        $data['isdelete'] = IS_DELETE;

        $result = $this->where($options)->save($data);
        return $result === false ? false : true;
    }
}
